import { Router } from 'express';
import { AdminVenueController } from '../../api/controllers/adminVenueController';
import { authenticate, authorize } from '../../middleware/auth';
import { ALL_PERMISSIONS } from '../../constants/permissions';

const router = Router();
const venueController = new AdminVenueController();

/**
 * @swagger
 * /api/admin/venues:
 *   get:
 *     summary: 获取场馆列表
 *     tags: [管理后台-场馆管理]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: query
 *         name: page
 *         schema:
 *           type: integer
 *         description: 页码
 *       - in: query
 *         name: pageSize
 *         schema:
 *           type: integer
 *         description: 每页数量
 *       - in: query
 *         name: keyword
 *         schema:
 *           type: string
 *         description: 搜索关键字
 *       - in: query
 *         name: status
 *         schema:
 *           type: string
 *         description: 状态筛选
 *       - in: query
 *         name: city
 *         schema:
 *           type: string
 *         description: 城市筛选
 *       - in: query
 *         name: country
 *         schema:
 *           type: string
 *         description: 国家筛选
 *     responses:
 *       200:
 *         description: 获取成功
 *       401:
 *         description: 未授权
 *       403:
 *         description: 权限不足
 */
router.get('/', 
  authenticate, 
  authorize([ALL_PERMISSIONS.VENUE_READ]), 
  venueController.getVenues
);

/**
 * @swagger
 * /api/admin/venues/stats:
 *   get:
 *     summary: 获取场馆统计信息
 *     tags: [管理后台-场馆管理]
 *     security:
 *       - bearerAuth: []
 *     responses:
 *       200:
 *         description: 获取成功
 *       401:
 *         description: 未授权
 *       403:
 *         description: 权限不足
 */
router.get('/stats', 
  authenticate, 
  authorize([ALL_PERMISSIONS.VENUE_READ]), 
  venueController.getVenueStats
);

/**
 * @swagger
 * /api/admin/venues/{id}:
 *   get:
 *     summary: 获取场馆详情
 *     tags: [管理后台-场馆管理]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *         description: 场馆ID
 *     responses:
 *       200:
 *         description: 获取成功
 *       400:
 *         description: 无效的场馆ID
 *       404:
 *         description: 场馆不存在
 *       401:
 *         description: 未授权
 *       403:
 *         description: 权限不足
 */
router.get('/:id', 
  authenticate, 
  authorize([ALL_PERMISSIONS.VENUE_READ]), 
  venueController.getVenueById
);

/**
 * @swagger
 * /api/admin/venues/{venueId}/floors:
 *   get:
 *     summary: 根据场地ID获取楼层列表
 *     tags: [管理后台-场馆管理]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: venueId
 *         required: true
 *         schema:
 *           type: integer
 *         description: 场地ID
 *     responses:
 *       200:
 *         description: 获取成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: 获取楼层列表成功
 *                 data:
 *                   type: array
 *                   items:
 *                     type: object
 *                     properties:
 *                       id:
 *                         type: integer
 *                         description: 楼层ID
 *                       name:
 *                         type: string
 *                         description: 楼层名称
 *                       level:
 *                         type: integer
 *                         description: 楼层级别
 *                       description:
 *                         type: string
 *                         description: 楼层描述
 *                       status:
 *                         type: string
 *                         description: 楼层状态
 *                       createdAt:
 *                         type: string
 *                         description: 创建时间
 *                       updatedAt:
 *                         type: string
 *                         description: 更新时间
 *       400:
 *         description: 无效的场地ID
 *       404:
 *         description: 场地不存在
 *       401:
 *         description: 未授权
 *       403:
 *         description: 权限不足
 */
router.get('/:venueId/floors', 
  authenticate, 
  authorize([ALL_PERMISSIONS.VENUE_READ]), 
  venueController.getFloorsByVenue
);

/**
 * @swagger
 * /api/admin/venues:
 *   post:
 *     summary: 创建场馆
 *     tags: [管理后台-场馆管理]
 *     security:
 *       - bearerAuth: []
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             required:
 *               - name
 *               - address
 *               - city
 *               - country
 *             properties:
 *               name:
 *                 type: string
 *                 description: 场馆名称
 *               description:
 *                 type: string
 *                 description: 场馆描述
 *               address:
 *                 type: string
 *                 description: 场馆地址
 *               city:
 *                 type: string
 *                 description: 城市
 *               country:
 *                 type: string
 *                 description: 国家
 *               capacity:
 *                 type: integer
 *                 description: 场馆容量
 *               contactPhone:
 *                 type: string
 *                 description: 联系电话
 *               contactEmail:
 *                 type: string
 *                 description: 联系邮箱
 *               website:
 *                 type: string
 *                 description: 网站地址
 *               latitude:
 *                 type: number
 *                 description: 纬度
 *               longitude:
 *                 type: number
 *                 description: 经度
 *               status:
 *                 type: string
 *                 enum: [ACTIVE, INACTIVE, MAINTENANCE]
 *                 description: 状态
 *     responses:
 *       201:
 *         description: 创建成功
 *       400:
 *         description: 数据验证失败
 *       401:
 *         description: 未授权
 *       403:
 *         description: 权限不足
 */
router.post('/', 
  authenticate, 
  authorize([ALL_PERMISSIONS.VENUE_CREATE]), 
  venueController.createVenue
);

/**
 * @swagger
 * /api/admin/venues/{id}:
 *   put:
 *     summary: 更新场馆
 *     tags: [管理后台-场馆管理]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *         description: 场馆ID
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               name:
 *                 type: string
 *                 description: 场馆名称
 *               description:
 *                 type: string
 *                 description: 场馆描述
 *               address:
 *                 type: string
 *                 description: 场馆地址
 *               city:
 *                 type: string
 *                 description: 城市
 *               country:
 *                 type: string
 *                 description: 国家
 *               capacity:
 *                 type: integer
 *                 description: 场馆容量
 *               contactPhone:
 *                 type: string
 *                 description: 联系电话
 *               contactEmail:
 *                 type: string
 *                 description: 联系邮箱
 *               website:
 *                 type: string
 *                 description: 网站地址
 *               latitude:
 *                 type: number
 *                 description: 纬度
 *               longitude:
 *                 type: number
 *                 description: 经度
 *               status:
 *                 type: string
 *                 enum: [ACTIVE, INACTIVE, MAINTENANCE]
 *                 description: 状态
 *     responses:
 *       200:
 *         description: 更新成功
 *       400:
 *         description: 数据验证失败
 *       404:
 *         description: 场馆不存在
 *       401:
 *         description: 未授权
 *       403:
 *         description: 权限不足
 */
router.put('/:id', 
  authenticate, 
  authorize([ALL_PERMISSIONS.VENUE_UPDATE]), 
  venueController.updateVenue
);

/**
 * @swagger
 * /api/admin/venues/{id}:
 *   delete:
 *     summary: 删除场馆
 *     tags: [管理后台-场馆管理]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *         description: 场馆ID
 *     responses:
 *       200:
 *         description: 删除成功
 *       400:
 *         description: 无效的场馆ID或场馆下存在关联数据
 *       404:
 *         description: 场馆不存在
 *       401:
 *         description: 未授权
 *       403:
 *         description: 权限不足
 */
router.delete('/:id', 
  authenticate, 
  authorize([ALL_PERMISSIONS.VENUE_DELETE]), 
  venueController.deleteVenue
);

/**
 * @swagger
 * /api/admin/venues/batch-status:
 *   put:
 *     summary: 批量更新场馆状态
 *     tags: [管理后台-场馆管理]
 *     security:
 *       - bearerAuth: []
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             required:
 *               - ids
 *               - status
 *             properties:
 *               ids:
 *                 type: array
 *                 items:
 *                   type: integer
 *                 description: 场馆ID数组
 *               status:
 *                 type: string
 *                 enum: [ACTIVE, INACTIVE, MAINTENANCE]
 *                 description: 新状态
 *     responses:
 *       200:
 *         description: 更新成功
 *       400:
 *         description: 数据验证失败
 *       401:
 *         description: 未授权
 *       403:
 *         description: 权限不足
 */
router.put('/batch-status', 
  authenticate, 
  authorize([ALL_PERMISSIONS.VENUE_UPDATE]), 
  venueController.batchUpdateVenueStatus
);

export default router;
